package logic

import (
	"context"
	"shop-ease/model"

	"shop-ease/shoprpc/internal/svc"
	"shop-ease/shoprpc/shoprpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CartAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCartAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CartAddLogic {
	return &CartAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CartAddLogic) CartAdd(in *shoprpc.CartAddRequest) (*shoprpc.CartAddResponse, error) {
	// todo: add your logic here and delete this line

	cart := model.Cart{

		ShopId:   int(in.ShopId),
		Quantity: int(in.Quantity),
		Money:    float64(in.Money),
	}
	model.DB.Debug().Create(&cart)
	return &shoprpc.CartAddResponse{
		CartId: int64(cart.ID),
	}, nil
}
